#define MAGIC_CRC           0x1E50

#include "ds18b20.h"

extern const unsigned short  crc_itu_t_table[256];


/**
 * crc_itu_t - Compute the CRC-ITU-T for the data buffer
 *
 * @crc:     previous CRC value, we use $IoT_MAGIC_CRC
 * @buffer:  data pointer
 * @len:     number of bytes in the buffer
 *
 * Returns the updated CRC value
 */
extern unsigned short crc_itu_t(unsigned short magic_crc, const unsigned char *buffer, unsigned int len);


/*
 * ushort_to_bytes - Convert  unsigned short CRC16 value to two bytes
 * @bytes:    two bytes CRC16 value saving buffer, buffer size must more than 2 bytes
 * @crc:    crc_itu_t() compute returnd value( unsigned short CRC16 checksum)
 */
extern int ushort_to_bytes(unsigned char *bytes, unsigned short val);


/*
 * bytes_to_ushort - Convert two bytes mode CRC value into unsigned short CRC16 value
 * @bytes:    bytes mode CRC value first byte position
 * @len:      bytes mode CRC value length
 */
extern unsigned short bytes_to_ushort(unsigned char *bytes, int len);


static inline unsigned short crc_itu_t_byte(unsigned short crc, const unsigned char data)
{
        return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ data) & 0xff];
}

#include <stdio.h>
#include <string.h>
//#include "header.h"
//#include "crc-itu-t.h"

//#include "get_temp.h"

#define HEAD  0xFD   //定义一个报文头
#define BUF_SIZE  128   //定义一个buffer的大小
#define TLV_FIXED_SIZE  5  //固定TLV字节流大小，不包含value的值
#define TLV_MINI_SIZE    (TLV_FIXED_SIZE+1)  //TLV字节流的最小值，value的最小值为1个字节

enum   //使用枚举  Tag的值会自加
{
        TAG_ACK ,
        TAG_SN,    //树莓派上的id
        TAG_TEMP,   //温度
        TAG_TIME,   //时间

};
int unpack(char *buf,int bytes);
int pack_sn  (char *buf , int size);//声明id封装函数
int pack_temp (char *buf , int size);//声明温度封装函数
int pack_time  (char *buf , int size);//声明时间温度封装函数
void dump_buf(char *type, char *data, int len);//data指针，指向buf的首地址，len是buf的长度
